from __future__ import with_statement

import unittest

import logging

import numpy, scipy

import common, test_util, retraction_unfolding_filter

logger = logging.getLogger("retraction_unfolding_filter_test")
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.INFO)

class RetractionCurveTest(unittest.TestCase):

    def test_reversed_stretch_at_end(self):
        k = 0.15
        v = 2180e-9
        cl_range = 15e-9, 21e-9
        rc = retraction_unfolding_filter.RetractionCurve("", k, v, [])
        actual = rc.last_reversed_stretch_at_end(cl_range, False)
        self.assertEquals(actual, [])
        peak0 = retraction_unfolding_filter.RetractionPeak(
            100e-9, 10e-12, 150e-12, 90e-9)
        rc = retraction_unfolding_filter.RetractionCurve("", k, v, [peak0])
        for detachment_strictly_largest in (False, True):
            actual = rc.last_reversed_stretch_at_end(
                cl_range, detachment_strictly_largest)
            self.assertEquals(actual, [])
        peak1 = retraction_unfolding_filter.RetractionPeak(
            118e-9, 10e-12, 200e-12, 100e-9)
        for detachment_strictly_largest in (False, True):
            actual = retraction_unfolding_filter.RetractionCurve(
                "", k, v, [peak0, peak1]).last_reversed_stretch_at_end(
                cl_range, detachment_strictly_largest)
            self.assertEquals(actual, [peak0])
        peak2 = retraction_unfolding_filter.RetractionPeak(
            136e-9, 10e-12, 190e-12, 130e-9)
        actual = retraction_unfolding_filter.RetractionCurve(
            "", k, v, [peak0, peak1, peak2]).last_reversed_stretch_at_end(
            cl_range, False)
        self.assertEquals(actual, [peak1, peak0])
        actual = retraction_unfolding_filter.RetractionCurve(
            "", k, v, [peak0, peak1, peak2]).last_reversed_stretch_at_end(
            cl_range, True)
        self.assertEquals(actual, [])


if __name__ == "__main__":
    test_util.initialise_seeds()
    suite = unittest.TestLoader().loadTestsFromTestCase(RetractionCurveTest)
    unittest.TextTestRunner(verbosity=2).run(suite)
